<?php
/**
 * Date: 10/28/12
 * Time: 9:52 PM
 * User: Amitav Roy
 */
class Bills extends CI_Controller{
	function __construct() {
		parent::__construct();

		// This is restricted area.
		auth_user();

		// Loading the model
		$this->load->model('bills_m');
	}

	/**
	 * The index page will never be used as the home page.
	 * Will be routing to view page instead.
	 */
	function index() {
		// Redirecting to home page.
		redirect('bills/view');
	}

	/**
	 * This is the home page of this section.
	 * Landing page showing the list of the bills payed in a table.
	 */
	function view() {
		// Setting up the data for the view.
		$data['pagetitle'] = 'View bills payed';
		$data['subheading'] = 'Bills payed so far';
		$data['scripts']['bills'] = 'bills'; // Including the javascript.
		$data['viewname'] = 'view_v.php';
		$data['viewdata'] = $this->bills_m->view_bills_payed(); // Data from the model
		$data['datacount'] = $this->bills_m->bills_payed_count(); // The count of bills payed

		$this->load->view('master', $data);
	}

	/**
	 * This is the page where I am rendering the form
	 * for entering a bill payment.
	 *
	 * The post data is send to pay_bill page.
	 */
	function pay() {
		$data['pagetitle'] = 'Pay a bill';
		$data['subheading'] = 'Pay a bill and enter the details.';
		$data['viewname'] = 'add_v.php';
		$data['viewdata'] = false;

		$this->load->view('master', $data);
	}

	/**
	 * This is the form action page for submitting the bill.
	 * This is using the model function to insert the data.
	 */
	function pay_bill() {
		if (isset($_POST) && $_POST['save'] == 'Save') {
			// Setting up the data before sending for insert.
			$data['amount'] = $this->input->post('amount');
			$data['date'] = $this->input->post('date');
			$data['brid'] = $this->input->post('biller');
			$data['description'] = $this->input->post('particulars');

			// Calling the model function which will handle the insert of the data.
			$this->bills_m->add_bill_payed($data);

			// Set the message for the user
			set_message('The bill payment data is added successfully.');

			// Redirect the user to the page
			redirect('bills/index');
		}
		else {
			redirect('bills/index');
		}
	}

	function edit() {

	}

	/**
	 * This is the page where I will be deleting the bill record.
	 */
	function delete() {

	}
}

/* End of file bills.php */
/* Location: ./application/controllers/bills.php */